package com.ct.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.ct.model.bo.MapStructBo;
import com.ct.model.convert.MapStrucConvertVoToBo;
import com.ct.model.vo.MapStructVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;


/**
 * MapStruct测试
 */
@RestController
@RequestMapping("/mapstruct")
@Slf4j
public class MapStructController {

    @Autowired
    public MapStrucConvertVoToBo mapStrucConvertVoToBo;

    /**
     * post日志测试层
     */
    @PostMapping("/post")
    public MapStructBo MapStructPost(@RequestBody MapStructVo mapStructVo) {
        log.info("mapStructVo-------------------------->{}",mapStructVo);
        log.info("Convert.toStr(mapStructVo)----------->{}", Convert.toStr(mapStructVo));
        log.info("mapStructVo.toString()--------------->{}",mapStructVo.toString());
        log.info("JSONUtil.toJsonStr(mapStructVo)------>{}",JSONUtil.toJsonStr(mapStructVo));
        log.info("mapStructVo---JSONConfig------------->{}",JSONUtil.toJsonStr(mapStructVo,new JSONConfig().setNatureKeyComparator().setIgnoreNullValue(false)));
        Console.log("mapStructVo---JSONConfig------------->{}",JSONUtil.toJsonStr(mapStructVo,new JSONConfig().setNatureKeyComparator().setIgnoreNullValue(false)));
        Map beanMap = JSONUtil.toBean(JSONUtil.toJsonStr(mapStructVo, new JSONConfig().setNatureKeyComparator().setIgnoreNullValue(false)), Map.class);
        Console.log("beanMap--->{}",beanMap);
        Console.log("JSONConfig--->{}",JSONUtil.toJsonStr(beanMap,new JSONConfig().setNatureKeyComparator().setIgnoreNullValue(false)));



        MapStructBo convert = mapStrucConvertVoToBo.convert(mapStructVo);
         JSONConfig jsonConfig = new JSONConfig();
        jsonConfig.setIgnoreNullValue(false);


         Console.log("convert:{}",convert);
         Console.log("convert:{}",JSONUtil.toJsonStr(convert));
         Console.log("convert:{}",JSONUtil.toJsonStr(convert,jsonConfig));
         return convert;
    }

    @PostMapping("/add")
    public String a1(@RequestBody MapStructVo mapStructVo) {
        return "succs";
    }


    @PostMapping("/add/test")
    public String a2(@RequestBody MapStructVo mapStructVo) {
        return "succs";
    }



    @PostMapping("add/excel")
    public String addExcel(@RequestParam(name = "appChannelId") Integer appChannelId,
                                     @RequestParam(name = "operator") String operator,
                                     @RequestParam(name = "file") MultipartFile file) {
        Console.log("appChannelId:{}",appChannelId);
        Console.log("operator:{}",operator);
        Console.log("file:{}",file);
        return "sucess";
    }
}
